/**
 * Ecart
 * 
 * This file is part of Ecart.
 * 
 * Ecart is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Ecart is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Ecart.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @copyright   Copyright 2008-2009 E-Cart LLC
 * @license     GNU Public License V3.0
 */

Ecart.getUrl = function(url, disableSsl, front) {
    var prefix = Ecart.secureUrl;
    if (disableSsl) {
        prefix = Ecart.baseUrl;
    }
    if (!front) {
        prefix += Ecart.adminUrl;
    }
    if (url) {
        url = url.replace(new RegExp("^[/]+", "g"), "");
    } else {
        url = '';
    }
    return prefix + '/' + url;
};

Ext.ux.Table = {
     colorize: function() {
          $(".ecart-table tr").mouseover(function() {
               $(this).addClass("over");
          }).mouseout(function() {
               $(this).removeClass("over");
          });
          $(".ecart-table tr:even").addClass("even");
     }
};
Ext.onReady(function(){
     Ext.ux.Table.colorize();
});

/*tabs*/
function pdTabs(tabsetId, useBlocks){
    
     var ecartTabs = document.getElementById(tabsetId).getElementsByTagName('a');
     
    if (ecartTabs.length) {
          $(ecartTabs[0]).addClass('active');
     }
     if (useBlocks) {
        for (var i = 0; i < ecartTabs.length; i++) {
               ecartTabs[i].onclick = new Function("switchBlock(" + i + "); return false;");
               document.getElementById(ecartTabs[i].id + '-block').style.display = "none";
          }
          document.getElementById(ecartTabs[0].id + '-block').style.display = "block";
          $('#' + ecartTabs[0].id + '-block').removeClass('x-hidden');
     }
}

function switchBlock(i){
    var elem = document.getElementById('ecart-tabs').getElementsByTagName('a');
    
    for (var j = 0; j < elem.length; j++) {
        elem[j].className = "";
        document.getElementById(elem[j].id + '-block').style.display = "none";
    }
    document.getElementById(elem[i].id + '-block').style.display = "block";
    $('#' + elem[i].id + '-block').removeClass('x-hidden');
    elem[i].className = "active";
}
/*end of tabs*/